﻿using MT.CustomUserControl.ViewModels;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace MT.CustomUserControl.Views.UserControls
{
    public partial class WaveProgressControl : UserControl
    {
        private WaveProgressViewModel viewModel;
        public WaveProgressControl()
        {
            InitializeComponent();
        }

        private void wave_control_Loaded(object sender, RoutedEventArgs e)
        {
            if (DataContext != null)
            {
                viewModel = (WaveProgressViewModel)DataContext;
                UpdateProgressValueActionFunc();
            }
        }

        private void UpdateProgressValueActionFunc()
        {
            if (viewModel.ProgressValue >= 0 && MaxValue > 0)
            {
                double bl = viewModel.ProgressValue / MaxValue;
                WaveProgressHeight = (Height - 20) * bl;
                DisPlayValue = (bl * 100).ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                WaveProgressHeight = 0;
                DisPlayValue = "0";
            }
        }

        public static readonly DependencyProperty WaveProgressBackgroundProperty = DependencyProperty.Register("WaveProgressBackground", typeof(SolidColorBrush), typeof(WaveProgressControl), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#C2BBFA"))));

        /// <summary>
        /// 进度条背景色
        /// </summary>
        public SolidColorBrush WaveProgressBackground
        {
            get { return (SolidColorBrush)GetValue(WaveProgressBackgroundProperty); }
            set { SetValue(WaveProgressBackgroundProperty, value); }
        }

        public static readonly DependencyProperty WavePorgressBarColorProperty = DependencyProperty.Register("WavePorgressBarColor", typeof(SolidColorBrush), typeof(WaveProgressControl), new PropertyMetadata(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#7F70F4"))));

        /// <summary>
        /// 进度条颜色
        /// </summary>
        public SolidColorBrush WavePorgressBarColor
        {
            get { return (SolidColorBrush)GetValue(WavePorgressBarColorProperty); }
            set { SetValue(WavePorgressBarColorProperty, value); }
        }

        public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(SolidColorBrush), typeof(WaveProgressControl), new PropertyMetadata(Brushes.Black));

        /// <summary>
        /// 文字颜色
        /// </summary>
        public SolidColorBrush TextColor
        {
            get { return (SolidColorBrush)GetValue(TextColorProperty); }
            set { SetValue(TextColorProperty, value); }
        }

        public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxValue", typeof(double), typeof(WaveProgressControl), new PropertyMetadata(100.0));

        public double MaxValue
        {
            get { return (double)GetValue(MaxValueProperty); }
            set { SetValue(MaxValueProperty, value); }
        }

        public static readonly DependencyProperty DisPlayValueProperty = DependencyProperty.Register("DisPlayValue", typeof(string), typeof(WaveProgressControl), new PropertyMetadata("0"));

        public string DisPlayValue
        {
            get { return (string)GetValue(DisPlayValueProperty); }
            set { SetValue(DisPlayValueProperty, value); }
        }

        public static readonly DependencyProperty WaveProgressHeightProperty = DependencyProperty.Register("WaveProgressHeight", typeof(double), typeof(WaveProgressControl), new PropertyMetadata(default(double)));

        /// <summary>
        /// 次属性不要手动设置
        /// </summary>
        public double WaveProgressHeight
        {
            get { return (double)GetValue(WaveProgressHeightProperty); }
            set { SetValue(WaveProgressHeightProperty, value); }
        }

    }
}
